package everydayone.longestCommonPrefix;

/**
 * @date 2020/06/15
 * @author 王光浩
 * @thinking 使用暴力法
 * @analysis 时间复杂度O（n*m），空间复杂度O（m）
 */
public class MyMethodOne {

	public String longestCommonPrefix(String[] strs) {
		StringBuilder sb = new StringBuilder();
		sb.append("");
		if (strs == null || strs.length == 0)
			return sb.toString();
		int len = strs.length;
		boolean flag = true;
		int index = 0;
		while (flag) {
			if (strs[0].length() <= index) {
				break;
			}
			char c = strs[0].charAt(index);
			for (int i = 1; i < len; i++) {
				if (strs[i].length() <= index || strs[i].charAt(index) != c) {
					flag = false;
				}
			}
			if (flag) {
				index++;
				sb.append(c);
			}
		}
		return sb.toString();
	}

}
